# delimit ;
clear ;
set more off ;
est drop _all ;
cd "R:/personlig/fenellac/menarche_replication/analysis/";

global plusdir "R:/personlig/fenellac/stata_ado/plus/";
sysdir set PLUS $plusdir ;
adopath ++ $plusdir ;

* **************************************************************************** ;
* This code replicates Appendix D, Figure 1.
*
* Paper: "Age of Marriage and Women's Political Engagement: Evidence from India"
* Authors: Fenella Carpena, Francesca Jensenius
* 
* Code by Fenella Carpena
* Last update: April 29, 2020
* **************************************************************************** ;

****************************************************************************** ;
* select the sample
****************************************************************************** ;

use "./input/eligible-women-ihds02-lhs.dta", clear ;
merge 1:1 IDHH PERSONID using "./input/eligible-women-ihds02-rhs.dta";
tab _merge ;
assert _merge == 3 ;
drop _merge ;

* keep only women who are married only once (i.e., have not ever remarried) ;
drop if ever_remarried == 1 ;
  
* keep only women age of menarche between 11-18 (1st-99th pctile) ; 
summ menarche_age ;
keep if menarche_age >= 11 & menarche_age <= 18 ;

* generating district identifier ;
egen dt_id = group(STATEID DISTID) ;

****************************************************************************** ;
* FIGURE: menarche age by mother's education
****************************************************************************** ;

* FULL SAMPLE ;
twoway 
(kdensity menarche_age if mother_ever_schooled == 1, bwidth(1))
(kdensity menarche_age if mother_ever_schooled == 0, bwidth(1) lpattern(shortdash)),
legend(order(1 "Mother Educated >> "2 "Mother Uneducated")) xtitle("Menarche Age") ytitle("Kernel Density") scheme(s2mono) ;  

graph export "./output/figure-menarche-age-by-mother-educ-full.png", replace ;

* RURAL WOMEN ;
twoway 
(kdensity menarche_age if mother_ever_schooled == 1 & rural == 1, bwidth(1))
(kdensity menarche_age if mother_ever_schooled == 0 & rural == 1, bwidth(1) lpattern(shortdash)),
legend(order(1 "Mother Educated >> "2 "Mother Uneducated")) xtitle("Menarche Age") ytitle("Kernel Density") scheme(s2mono) ;  

graph export "./output/figure-menarche-age-by-mother-educ-rural.png", replace ;

* URBAN WOMEN ;
twoway 
(kdensity menarche_age if mother_ever_schooled == 1 & rural == 0, bwidth(1))
(kdensity menarche_age if mother_ever_schooled == 0 & rural == 0, bwidth(1) lpattern(shortdash)),
legend(order(1 "Mother Educated >> "2 "Mother Uneducated")) xtitle("Menarche Age") ytitle("Kernel Density") scheme(s2mono) ;  

graph export "./output/figure-menarche-age-by-mother-educ-urban.png", replace ;

****************************************************************************** ;
* FIGURE: menarche age by father's education
****************************************************************************** ;
 
* FULL SAMPLE ;
twoway 
(kdensity menarche_age if father_ever_schooled == 1, bwidth(1))
(kdensity menarche_age if father_ever_schooled == 0, bwidth(1) lpattern(shortdash)),
legend(order(1 "Father Educated >> "2 "Father Uneducated")) xtitle("Menarche Age") ytitle("Kernel Density") scheme(s2mono) ;  

graph export "./output/figure-menarche-age-by-father-educ-full.png", replace ;

* RURAL SAMPLE ;
twoway 
(kdensity menarche_age if father_ever_schooled == 1 & rural == 1, bwidth(1))
(kdensity menarche_age if father_ever_schooled == 0 & rural == 1, bwidth(1) lpattern(shortdash)),
legend(order(1 "Father Educated >> "2 "Father Uneducated")) xtitle("Menarche Age") ytitle("Kernel Density") scheme(s2mono) ;  

graph export "./output/figure-menarche-age-by-father-educ-rural.png", replace ;

* URBAN SAMPLE ;
twoway 
(kdensity menarche_age if father_ever_schooled == 1 & rural == 0, bwidth(1))
(kdensity menarche_age if father_ever_schooled == 0 & rural == 0, bwidth(1) lpattern(shortdash)),
legend(order(1 "Father Educated >> "2 "Father Uneducated")) xtitle("Menarche Age") ytitle("Kernel Density") scheme(s2mono) ;  

graph export "./output/figure-menarche-age-by-father-educ-urban.png", replace ;

****************************************************************************** ;
* FIGURE: menarche age by caste
****************************************************************************** ;

gen caste_low = sc == 1 | st == 1 | obc == 1 ; 

* FULL SAMPLE ;
twoway
(kdensity menarche_age if caste_low == 1 , bwidth(1))
(kdensity menarche_age if caste_low == 0 , bwidth(1) lpattern(shortdash)),
legend(order(1 "SC/ST/OBC >> "2 "Other")) xtitle("Menarche Age") ytitle("Kernel Density") scheme(s2mono) ;  

graph export "./output/figure-menarche-age-by-caste-full.png", replace ;

* RURAL SAMPLE ;
twoway
(kdensity menarche_age if caste_low == 1 & rural == 1 , bwidth(1))
(kdensity menarche_age if caste_low == 0 & rural == 1 , bwidth(1) lpattern(shortdash)),
legend(order(1 "SC/ST/OBC >> "2 "Other")) xtitle("Menarche Age") ytitle("Kernel Density") scheme(s2mono) ;  

graph export "./output/figure-menarche-age-by-caste-rural.png", replace ;

* URBAN SAMPLE ;
twoway
(kdensity menarche_age if caste_low == 1 & rural == 0 , bwidth(1))
(kdensity menarche_age if caste_low == 0 & rural == 0 , bwidth(1) lpattern(shortdash)),
legend(order(1 "SC/ST/OBC >> "2 "Other")) xtitle("Menarche Age") ytitle("Kernel Density") scheme(s2mono) ;  

graph export "./output/figure-menarche-age-by-caste-urban.png", replace ;

****************************************************************************** ;
* FIGURE: menarche age by religion
****************************************************************************** ;

* FULL SAMPLE ;
twoway 
(kdensity menarche_age if hindu == 1, bwidth(1))
(kdensity menarche_age if hindu == 0, bwidth(1) lpattern(shortdash)) ,
legend(order(1 "Hindu >> "2 "Non-Hindu")) xtitle("Menarche Age") ytitle("Kernel Density") scheme(s2mono) ;  

graph export "./output/figure-menarche-age-by-religion-full.png", replace ;

* RURAL SAMPLE ;
twoway 
(kdensity menarche_age if hindu == 1 & rural == 1, bwidth(1))
(kdensity menarche_age if hindu == 0 & rural == 1, bwidth(1) lpattern(shortdash)) ,
legend(order(1 "Hindu >> "2 "Non-Hindu")) xtitle("Menarche Age") ytitle("Kernel Density") scheme(s2mono) ;  

graph export "./output/figure-menarche-age-by-religion-rural.png", replace ;

* URBAN SAMPLE ;
twoway 
(kdensity menarche_age if hindu == 1 & rural == 0, bwidth(1))
(kdensity menarche_age if hindu == 0 & rural == 0, bwidth(1) lpattern(shortdash)) ,
legend(order(1 "Hindu >> "2 "Non-Hindu")) xtitle("Menarche Age") ytitle("Kernel Density") scheme(s2mono) ;  

graph export "./output/figure-menarche-age-by-religion-urban.png", replace ;

****************************************************************************** ;
* LaTeX File for Figures
****************************************************************************** ;
shell echo \begin{figure} > "./output/figure-menarche-age-comparison.tex";

shell echo \caption{Distribution of Menarche Age by Respondent Characteristics}\label{figure-menarche-age-comparison} >> "./output/figure-menarche-age-comparison.tex"; 
shell echo \centering >> "./output/figure-menarche-age-comparison.tex";

* Panel A: Mother's Education ;
shell echo Panel A: Mother's Education \\ \smallskip >> "./output/figure-menarche-age-comparison.tex";
shell echo \begin{subfigure}[b]{0.305\textwidth} >> "./output/figure-menarche-age-comparison.tex";
shell echo \includegraphics[width=\textwidth]{./analysis/output/figure-menarche-age-by-mother-educ-full.png} >> "./output/figure-menarche-age-comparison.tex";
shell echo \caption{Rural and Urban Women} >> "./output/figure-menarche-age-comparison.tex";
shell echo \end{subfigure} >> "./output/figure-menarche-age-comparison.tex";

shell echo \begin{subfigure}[b]{0.305\textwidth} >> "./output/figure-menarche-age-comparison.tex";
shell echo \includegraphics[width=\textwidth]{./analysis/output/figure-menarche-age-by-mother-educ-rural.png} >> "./output/figure-menarche-age-comparison.tex";
shell echo \caption{Rural Women} >> "./output/figure-menarche-age-comparison.tex";
shell echo \end{subfigure} >> "./output/figure-menarche-age-comparison.tex";

shell echo \begin{subfigure}[b]{0.305\textwidth} >> "./output/figure-menarche-age-comparison.tex";
shell echo \includegraphics[width=\textwidth]{./analysis/output/figure-menarche-age-by-mother-educ-urban.png} >> "./output/figure-menarche-age-comparison.tex";
shell echo \caption{Urban Women} >> "./output/figure-menarche-age-comparison.tex";
shell echo \end{subfigure} >> "./output/figure-menarche-age-comparison.tex";
shell echo ~ >> "./output/figure-menarche-age-comparison.tex";

* Panel B: Fathers's Education  ;
shell echo Panel B: Father's Education \\ \smallskip \setcounter{subfigure}{0} >> "./output/figure-menarche-age-comparison.tex";
shell echo \begin{subfigure}[b]{0.305\textwidth} >> "./output/figure-menarche-age-comparison.tex";
shell echo \includegraphics[width=\textwidth]{./analysis/output/figure-menarche-age-by-father-educ-full.png} >> "./output/figure-menarche-age-comparison.tex";
shell echo \caption{Rural and Urban Women} >> "./output/figure-menarche-age-comparison.tex";
shell echo \end{subfigure} >> "./output/figure-menarche-age-comparison.tex";

shell echo \begin{subfigure}[b]{0.305\textwidth} >> "./output/figure-menarche-age-comparison.tex";
shell echo \includegraphics[width=\textwidth]{./analysis/output/figure-menarche-age-by-father-educ-rural.png} >> "./output/figure-menarche-age-comparison.tex";
shell echo \caption{Rural Women} >> "./output/figure-menarche-age-comparison.tex";
shell echo \end{subfigure} >> "./output/figure-menarche-age-comparison.tex";

shell echo \begin{subfigure}[b]{0.305\textwidth} >> "./output/figure-menarche-age-comparison.tex";
shell echo \includegraphics[width=\textwidth]{./analysis/output/figure-menarche-age-by-father-educ-urban.png} >> "./output/figure-menarche-age-comparison.tex";
shell echo \caption{Urban Women} >> "./output/figure-menarche-age-comparison.tex";
shell echo \end{subfigure} >> "./output/figure-menarche-age-comparison.tex";
shell echo ~ >> "./output/figure-menarche-age-comparison.tex";

* Panel C: Caste ;
shell echo Panel C: Caste \\ \smallskip \setcounter{subfigure}{0} >> "./output/figure-menarche-age-comparison.tex";
shell echo \begin{subfigure}[b]{0.305\textwidth} >> "./output/figure-menarche-age-comparison.tex";
shell echo \includegraphics[width=\textwidth]{./analysis/output/figure-menarche-age-by-caste-full.png} >> "./output/figure-menarche-age-comparison.tex";
shell echo \caption{Rural and Urban Women} >> "./output/figure-menarche-age-comparison.tex";
shell echo \end{subfigure} >> "./output/figure-menarche-age-comparison.tex";

shell echo \begin{subfigure}[b]{0.305\textwidth} >> "./output/figure-menarche-age-comparison.tex";
shell echo \includegraphics[width=\textwidth]{./analysis/output/figure-menarche-age-by-caste-rural.png} >> "./output/figure-menarche-age-comparison.tex";
shell echo \caption{Rural Women} >> "./output/figure-menarche-age-comparison.tex";
shell echo \end{subfigure} >> "./output/figure-menarche-age-comparison.tex";

shell echo \begin{subfigure}[b]{0.305\textwidth} >> "./output/figure-menarche-age-comparison.tex";
shell echo \includegraphics[width=\textwidth]{./analysis/output/figure-menarche-age-by-caste-urban.png} >> "./output/figure-menarche-age-comparison.tex";
shell echo \caption{Urban Women} >> "./output/figure-menarche-age-comparison.tex";
shell echo \end{subfigure} >> "./output/figure-menarche-age-comparison.tex";
shell echo ~ >> "./output/figure-menarche-age-comparison.tex";

* Panel D: Religion ;
shell echo Panel D: Religion \\ \smallskip \setcounter{subfigure}{0} >> "./output/figure-menarche-age-comparison.tex";
shell echo \begin{subfigure}[b]{0.305\textwidth} >> "./output/figure-menarche-age-comparison.tex";
shell echo \includegraphics[width=\textwidth]{./analysis/output/figure-menarche-age-by-religion-full.png} >> "./output/figure-menarche-age-comparison.tex";
shell echo \caption{Rural and Urban Women} >> "./output/figure-menarche-age-comparison.tex";
shell echo \end{subfigure} >> "./output/figure-menarche-age-comparison.tex";

shell echo \begin{subfigure}[b]{0.305\textwidth} >> "./output/figure-menarche-age-comparison.tex";
shell echo \includegraphics[width=\textwidth]{./analysis/output/figure-menarche-age-by-religion-rural.png} >> "./output/figure-menarche-age-comparison.tex";
shell echo \caption{Rural Women} >> "./output/figure-menarche-age-comparison.tex";
shell echo \end{subfigure} >> "./output/figure-menarche-age-comparison.tex";

shell echo \begin{subfigure}[b]{0.305\textwidth} >> "./output/figure-menarche-age-comparison.tex";
shell echo \includegraphics[width=\textwidth]{./analysis/output/figure-menarche-age-by-religion-urban.png} >> "./output/figure-menarche-age-comparison.tex";
shell echo \caption{Urban Women} >> "./output/figure-menarche-age-comparison.tex";
shell echo  \end{subfigure} >> "./output/figure-menarche-age-comparison.tex";

shell echo \caption*{\footnotesize \textit{Notes:} This figure plots the distribution of 
menarche age by respondent characteristics. The first two panels are based on the 
education of the respondent's parents, where educated is defined as ever attended school. 
The last two panels are based on the caste and religion, respectively, of the respondent's spousal household. 
SC, ST and OBC refer to Scheduled Caste, Scheduled Tribe, and Other Backward Class. 
Data from IHDS 2011-12. Epanechnikov kernel with bandwidth equal to one.} >> "./output/figure-menarche-age-comparison.tex";
shell echo \end{figure} >> "./output/figure-menarche-age-comparison.tex";

exit ;
